#include <string.h>
#include <stdio.h>

#define NODES_NR 256
typedef char node;
node v[NODES_NR];

#define key(A) (A)
#define less(A, B) (key(A) < key(B))
#define exch(A, B) { node t = A; A = B; B = t; }

int partition(node* , int , int );
void qsort(node* , int , int ); // sortowanie szybkie

int main()
{
  int n; // nodes number
  strcpy(v, "QUICKSORT");
  n = strlen(v);
  qsort(v, 0, n-1);
  //int i; for (i = 0; i < n; i++) printf("%c", v[i]);
  return 0;
}

int partition(node *v, int l, int r)
{ 
  int i = l-1, j = r; 
  node vi = v[r];
  for (;;)
    { 
      while (less(v[++i], vi)) ;
      while (less(vi, v[--j])) 
	if (j == l) break;
      if (i >= j) break;
      exch(v[i], v[j]);
    }
  exch(v[i], v[r]);
  return i;
}

void qsort(node v[], int l, int r)
{ 
  int pivot;
  if (r <= l) return;
  pivot = partition(v, l, r);
  qsort(v, l, pivot-1);
  qsort(v, pivot+1, r);
}

